//Copyright 2011 - Jonathan Allen

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics.Contracts;

namespace Granite.Testing
{
	/// <summary>
	/// Assertions for INotifyCollectionChanged
	/// </summary>
    public class CollectionChangedEventAssert : EventAssert<NotifyCollectionChangedEventArgs>
    {
        readonly INotifyCollectionChanged m_Source;


		/// <summary>
		/// Creates a new INotifyCollectionChanged assertion
		/// </summary>
		/// <param name="source"></param>
		public CollectionChangedEventAssert(INotifyCollectionChanged source)
			: base(source)
		{
			if (source == null)
				throw new ArgumentNullException("source", "source is null.");
			Contract.EndContractBlock();

			m_Source = source;
			m_Source.CollectionChanged += SourceEventFired;
		}

		/// <summary>
		/// Asserts that an event is in the queue and that it has the indicated properties.
		/// </summary>
		/// <param name="action">Expected action value.</param>
		/// <returns>This will remove the event from the queue.</returns>
        public EventPair<NotifyCollectionChangedEventArgs> Expect(NotifyCollectionChangedAction action)
        {
            //TODO: This needs to check the other fields on the eventEvent
            var nextEvent = Expect();
            Assert.AreEqual(action, nextEvent.EventArgs.Action, "The wrong action was set.");
            return nextEvent;
        }
    }
}
